<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns:job="livcos.org/ns/process/job"
  exclude-result-prefixes="html">
  
  <xsl:import href="list.xsl"/>

	<xsl:output method="html" encoding="UTF-8"
    doctype-public="-//W3C//DTD HTML 4.01//EN"
    doctype-system="http://www.w3.org/TR/html4/strict.dtd"/>
  
  <xsl:param name="ref"/>
  
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="/">
    <xsl:apply-templates select="document($ref)/*"/>
  </xsl:template>
  
  <xsl:template match="html:link">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="@href | @src">
  	<xsl:variable name="replace" select="$snapshot/replace[matches(current(), @pattern)][1]"/>
  	<xsl:variable name="resource" select="$snapshot/resource[contains(current(), @ref)][1]"/>
  	<xsl:attribute name="{name()}">
      <xsl:choose>
      	<xsl:when test="$replace">
      		<xsl:value-of select="replace(., $replace/@pattern, $replace/@value)"/>
      	</xsl:when>
      	<xsl:when test="$resource">
      		<xsl:value-of select="substring-before(.,$resource/@ref)"/>
      		<xsl:value-of select="$resource/@out"/>
      	</xsl:when>
      	<xsl:otherwise>
          <xsl:value-of select="."/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
  </xsl:template>
  
  <xsl:template match="html:head/html:script[ends-with(@src, 'script/init.js')]">
  </xsl:template>
  
	<xsl:template match="html:head/html:script[ends-with(@src, 'script/scripts.js')]">
	</xsl:template>
	
	<xsl:template match="html:div[starts-with(@class, 'task')]">
	</xsl:template>
	
</xsl:stylesheet>
